package com.raulraja.util.handler.impl;

import com.raulraja.processor.ProcessingEngine;
import com.raulraja.domain.Person;
import com.raulraja.domain.Place;
import org.springframework.web.HttpRequestHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Frontend entry point for the demo
 */
public class ServiceInvokerHandlerImpl implements HttpRequestHandler {

	/**
	 * The engine that processes object types
	 */
	private ProcessingEngine<Object> processingEngine;

	/**
	 * sets the engine that processes object types
	 * @param processingEngine the engine
	 */
	public void setProcessingEngine(ProcessingEngine<Object> processingEngine) {
		this.processingEngine = processingEngine;
	}

	/**
	 * Process the given request, generating a response.
	 *
	 * @param request  current HTTP request
	 * @param response current HTTP response
	 * @throws javax.servlet.ServletException in case of general errors
	 * @throws java.io.IOException			in case of I/O errors
	 */
	public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Person person = new Person();
		Place place = new Place();
		processingEngine.process(person);
		processingEngine.process(place);
	}
}
